<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
import Cookies from "js-cookie";
import { getToken, setToken } from "@/utils/auth";
export default {
  name: "App",
  metaInfo() {
    return {
      title:
        this.$store.state.settings.dynamicTitle &&
        this.$store.state.settings.title,
      titleTemplate: (title) => {
        return title
          ? `${title} - ${process.env.VUE_APP_TITLE}`
          : process.env.VUE_APP_TITLE;
      },
    };
  },
  created() {
    this.setAccessToken();
  },
  methods: {
    setAccessToken() {
      console.log("App");
      const access_token =
        window.localStorage.getItem("access_token") || getToken();
      if (!access_token) {
        const urlParams = new URLSearchParams(window.location.search);
        const token = urlParams.get("access_token");
        Cookies.set("username", "admin", { expires: 3600 * 24 * 365 * 20 });
        Cookies.set("password", "admin123", {
          expires: 3600 * 24 * 365 * 20,
        });
        Cookies.set("rememberMe", "1", {
          expires: 3600 * 24 * 365 * 20,
        });
        if (token) {
          window.localStorage.setItem("access_token", token);
          setToken(token);
          this.$store.commit("SET_TOKEN", token);
        }
      }
    },
  },
};
</script>
<style lang="stylus">
@import "base";
.el-cascader-menu__wrap{
  height: 300px;
}
#app{
  padding: 0 6px;
}
</style>
